package com.company.cloud.club.modules.db.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.company.cloud.club.modules.db.domain.ClubMember;
import com.company.cloud.club.modules.db.domain.UserInfo;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface ClubMemberMapper extends BaseMapper<ClubMember> {

    @Select("SELECT count(id) FROM club_member WHERE club_id = #{clubId, jdbcType=VARCHAR}")
    Integer countMember(@Param("clubId") String clubId);

    @Delete("DELETE FROM club_member WHERE club_id = #{clubId, jdbcType=VARCHAR} AND user_id = #{userId, jdbcType=INTEGER}")
    void removeMember(@Param("clubId") String clubId, @Param("userId") Integer userId);

    @Delete("DELETE FROM club_member WHERE club_id = #{clubId, jdbcType=VARCHAR} AND type = #{type, jdbcType=INTEGER}")
    boolean deleteClubMember(@Param("clubId") String clubId, @Param("type") String type);

    @Select("SELECT * FROM club_member WHERE club_id = #{clubId, jdbcType=VARCHAR}")
    List<ClubMember> selectByClubId(@Param("clubId") String clubId);

    @Select("SELECT * FROM club_member WHERE club_id = #{clubId, jdbcType=VARCHAR} limit #{pageStart}, #{pageEnd}")
    List<ClubMember> pageByClubId(@Param("clubId") String clubId,
                                @Param("pageStart") Integer pageStart,
                                @Param("pageEnd") Integer pageEnd);

    @Select("SELECT count(*) FROM club_member WHERE club_id = #{clubId, jdbcType=VARCHAR}")
    Integer countByClubId(@Param("clubId") String clubId);

    @Select("SELECT count(*) FROM club_member WHERE club_id = #{clubId, jdbcType=VARCHAR} AND user_id = #{currentUserId, jdbcType=INTEGER}")
    Integer isColled(@Param("clubId") String clubId,
                     @Param("currentUserId") Integer currentUserId);

    @Select("SELECT * FROM club_member WHERE club_id = #{clubId, jdbcType=VARCHAR} AND user_id = #{userId, jdbcType=INTEGER}")
    ClubMember selectByClubIdAndUserId(@Param("clubId") String resId,
                                       @Param("userId") Integer userId);

    @Select("SELECT * FROM club_member WHERE user_id = #{userId, jdbcType=INTEGER}")
    List<ClubMember> selectByUserId(@Param("userId") Integer userId);

    @Select("SELECT * FROM club_member WHERE user_id = #{userId, jdbcType=INTEGER} limit #{pageStart}, #{pageEnd}")
    List<ClubMember> pageByUserId(@Param("userId") Integer userId,
                                  @Param("pageStart") Integer pageStart,
                                  @Param("pageEnd") Integer pageEnd);

    @Select("SELECT count(*) FROM club_member WHERE user_id = #{userId, jdbcType=INTEGER}")
    int countByUserId(@Param("userId") Integer userId);

}